//
//  DiseaserTopView.m
//  International_Hospital
//
//  Created by 李建强 on 16/7/6.
//  Copyright © 2016年 LiYiLin. All rights reserved.
//

#import "DiseaserTopView.h"

@interface DiseaserTopView()

//@property (nonatomic,strong)UIImageView *picImageView;
@property (nonatomic,strong)UIButton *picButton;

@property (nonatomic,strong)UILabel *introduceLabel;

@property (nonatomic,strong)UIButton *button;
@end

@implementation DiseaserTopView


-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
//        self.contentView.backgroundColor = LIGHTBLUE_COLOR;
        self.contentView.backgroundColor = [UIColor clearColor];
        
        self.picButton = [UIButton buttonWithType:UIButtonTypeCustom];
        
//        self.picImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:self.picButton];
        
        [self.picButton addTarget:self action:@selector(clickPicButton:) forControlEvents:UIControlEventTouchUpInside];
        NSFileManager *manger = [NSFileManager defaultManager];
        
        if ([manger fileExistsAtPath:PATH]) {
            UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfFile:PATH]];
            [self.picButton setImage:image forState:UIControlStateNormal];
        }else{
            [self.picButton setImage:[UIImage imageNamed:@"Bill"] forState:UIControlStateNormal];
        }
        
        self.button = [[UIButton alloc]init];
        [self addSubview:self.button];
        [self.button setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.4]];
        [self.button setTitle:@"点击切换背景" forState:UIControlStateNormal];
        [self.button addTarget:self action:@selector(clickCutbg:) forControlEvents:UIControlEventTouchUpInside];
        
//        NSDictionary *attr = @{}
        
        NSAttributedString *attr = [[NSAttributedString alloc]initWithString:@"点击切换背景" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor blackColor]}];
        NSAttributedString *attr2 = [[NSAttributedString alloc]initWithString:@"点击切换背景" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:kThemeColor}];
        
        
        [self.button setAttributedTitle:attr forState:UIControlStateNormal];
        
        [self.button setAttributedTitle:attr2 forState:UIControlStateHighlighted];
        
        self.introduceLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.introduceLabel];
        self.introduceLabel.text = @"病人简介";
    }
    
    return self;
}


-(void)clickCutbg:(UIButton *)button{
    
    if ([self.clickDelegate respondsToSelector:@selector(clickDis:addClickButton:)]) {
        [self.clickDelegate clickDis:self addClickButton:button];
    }
    
}


-(void)layoutSubviews{
    [super layoutSubviews];

    
    
    self.picButton.layer.cornerRadius = self.picButton.frame.size.width/2;
    self.picButton.layer.masksToBounds = YES;
    [self.picButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.offset(10);
        make.left.offset(10);
        make.width.equalTo(self.contentView.mas_height).offset(-20);
        make.height.equalTo(self.contentView.mas_height).offset(-20);
    }];
    
    [self.introduceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.picButton.mas_top);
        make.left.equalTo(self.picButton.mas_right).offset(20);
    }];
    
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.equalTo(self).offset(-30);
        make.centerY.equalTo(self.mas_centerY);
        
    }];
    
}

-(void)clickPicButton:(UIButton*)button{
    if ([self.delegate respondsToSelector:@selector(diseasearTop:addPicButton:)]) {
        [self.delegate diseasearTop:self addPicButton:button];
    }
    
}

@end
